import dayjs from "dayjs";
import { ElMessageBox } from "element-plus";

export const imgUploadUrl = import.meta.env.VITE_IMG_UPLOAD_URL;

export const imgUrl = import.meta.env.VITE_IMG_URL;

export const validatePhone = (_rule: any, value: any, callback: any) => {
    // 手机号码验证规则
    const phoneRegex = /^1[3-9]\d{9}$/
    if (value == undefined) {
      callback()
    }
    if (value == null) {
      callback()
    }
    if (value == "null") {
      callback()
    }
    if (value == "") {
      callback()
    }
    if ((value === undefined) || phoneRegex.test(value)) {
      callback()
    } else {
      callback(new Error('请输入正确的手机号码'))
    }
  }

  export function checkTime(time: string): string {
    if (time) {
      return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
    } else {
      return ''
    }
  }


  export const deleteMsg = (fun: (row: any) => void, row?: any) => {
    ElMessageBox.confirm(
      "确定要删除吗",
      "提示",
      {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }
    )
      .then(() => {
        fun(row ? row : "");
      })
      .catch(() => {
      });
  }